// $Id: string.hpp 2 2009-09-02 08:47:42Z joseph2002 $
/*
 * Copyright 2008-2009 Joseph Wu
 * Distributed under the Boost Software License, Version 1.0.
 * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
 *
 * For more information, see http://xpcomplus.sourceforge.net
 */

#ifndef XPCOM_API_STRING_HPP
#define XPCOM_API_STRING_HPP

#include "config.hpp"
#include <xpcom/types.hpp>

#ifdef XPCOM_USE_INTERNAL_API
# define NS_StringContainerInit           NS_StringContainerInit_P
# define NS_StringContainerInit2          NS_StringContainerInit2_P
# define NS_StringContainerFinish         NS_StringContainerFinish_P
# define NS_StringGetData                 NS_StringGetData_P
# define NS_StringGetMutableData          NS_StringGetMutableData_P
# define NS_StringCloneData               NS_StringCloneData_P
# define NS_StringSetData                 NS_StringSetData_P
# define NS_StringSetDataRange            NS_StringSetDataRange_P
# define NS_StringCopy                    NS_StringCopy_P
# define NS_StringSetIsVoid               NS_StringSetIsVoid_P
# define NS_StringGetIsVoid               NS_StringGetIsVoid_P
# define NS_CStringContainerInit          NS_CStringContainerInit_P
# define NS_CStringContainerInit2         NS_CStringContainerInit2_P
# define NS_CStringContainerFinish        NS_CStringContainerFinish_P
# define NS_CStringGetData                NS_CStringGetData_P
# define NS_CStringGetMutableData         NS_CStringGetMutableData_P
# define NS_CStringCloneData              NS_CStringCloneData_P
# define NS_CStringSetData                NS_CStringSetData_P
# define NS_CStringSetDataRange           NS_CStringSetDataRange_P
# define NS_CStringCopy                   NS_CStringCopy_P
# define NS_CStringSetIsVoid              NS_CStringSetIsVoid_P
# define NS_CStringGetIsVoid              NS_CStringGetIsVoid_P
# define NS_CStringToUTF16                NS_CStringToUTF16_P
# define NS_UTF16ToCString                NS_UTF16ToCString_P
#endif // XPCOM_USE_INTERNAL_API

// AString
_XPCOM_API(xpcom::result_t)
NS_StringContainerInit(xpcom::wstring& aContainer);

#if XPCOM_API_VERSION >= XPCOM_API_VERSION_1_8
enum
{
    NS_STRING_CONTAINER_INIT_DEPEND    = (1 << 1),
    NS_STRING_CONTAINER_INIT_ADOPT     = (1 << 2),
    NS_STRING_CONTAINER_INIT_SUBSTRING = (1 << 3)
};

_XPCOM_API(xpcom::result_t)
NS_StringContainerInit2(
        xpcom::wstring& aContainer,
        const xpcom::wchar* aData, xpcom::uint32_t aDataLength,
        xpcom::uint32_t aFlags);
#endif // XPCOM_API_VERSION >= XPCOM_API_VERSION_1_8

_XPCOM_API(void)
NS_StringContainerFinish(xpcom::wstring& aContainer);

_XPCOM_API(xpcom::uint32_t)
NS_StringGetData(
        const xpcom::wstring& aStr,
        const xpcom::wchar** aData, xpcom::bool_t* aTerminated);

#if XPCOM_API_VERSION >= XPCOM_API_VERSION_1_8
_XPCOM_API(xpcom::uint32_t)
NS_StringGetMutableData(
        xpcom::wstring& aStr,
        xpcom::uint32_t aDataLength, xpcom::wchar** aData);
#endif // XPCOM_API_VERSION >= XPCOM_API_VERSION_1_8

_XPCOM_API(xpcom::wchar*)
NS_StringCloneData(const xpcom::wstring& aStr);

_XPCOM_API(xpcom::result_t)
NS_StringSetData(
        xpcom::wstring& aStr,
        const xpcom::wchar* aData, xpcom::uint32_t aDataLength);

_XPCOM_API(xpcom::result_t)
NS_StringSetDataRange(
        xpcom::wstring& aStr,
        xpcom::uint32_t aCutOffset, xpcom::uint32_t aCutLength,
        const xpcom::wchar* aData, xpcom::uint32_t aDataLength);

_XPCOM_API(xpcom::result_t)
NS_StringCopy(xpcom::wstring& aDestStr, const xpcom::wstring& aSrcStr);

#if XPCOM_API_VERSION >= XPCOM_API_VERSION_1_9
_XPCOM_API(void)
NS_StringSetIsVoid(xpcom::wstring& aStr, const xpcom::bool_t aIsVoid);

_XPCOM_API(xpcom::bool_t)
NS_StringGetIsVoid(const xpcom::wstring& aStr);
#endif // XPCOM_API_VERSION >= XPCOM_API_VERSION_1_9

// ACString
_XPCOM_API(xpcom::result_t)
NS_CStringContainerInit(xpcom::string& aContainer);

#if XPCOM_API_VERSION >= XPCOM_API_VERSION_1_8
enum
{
    NS_CSTRING_CONTAINER_INIT_DEPEND    = (1 << 1),
    NS_CSTRING_CONTAINER_INIT_ADOPT     = (1 << 2),
    NS_CSTRING_CONTAINER_INIT_SUBSTRING = (1 << 3)
};

_XPCOM_API(xpcom::result_t)
NS_CStringContainerInit2(
        xpcom::string& aContainer,
        const char* aData, xpcom::uint32_t aDataLength,
        xpcom::uint32_t aFlags);
#endif // XPCOM_API_VERSION >= XPCOM_API_VERSION_1_8

_XPCOM_API(void)
NS_CStringContainerFinish(xpcom::string& aContainer);

_XPCOM_API(xpcom::uint32_t)
NS_CStringGetData(
        const xpcom::string& aStr,
        const char** aData, xpcom::bool_t* aTerminated);

#if XPCOM_API_VERSION >= XPCOM_API_VERSION_1_8
_XPCOM_API(xpcom::uint32_t)
NS_CStringGetMutableData(
        xpcom::string& aStr,
        xpcom::uint32_t aDataLength, char** aData);
#endif // XPCOM_API_VERSION >= XPCOM_API_VERSION_1_8

_XPCOM_API(char*)
NS_CStringCloneData(const xpcom::string& aStr);

_XPCOM_API(xpcom::result_t)
NS_CStringSetData(
        xpcom::string& aStr,
        const char* aData, xpcom::uint32_t aDataLength);

_XPCOM_API(xpcom::result_t)
NS_CStringSetDataRange(
        xpcom::string& aStr,
        xpcom::uint32_t aCutOffset, xpcom::uint32_t aCutLength,
        const char* aData, xpcom::uint32_t aDataLength);

_XPCOM_API(xpcom::result_t)
NS_CStringCopy(xpcom::string& aDestStr, const xpcom::string& aSrcStr);

#if XPCOM_API_VERSION >= XPCOM_API_VERSION_1_9
_XPCOM_API(void)
NS_CStringSetIsVoid(xpcom::string& aStr, const xpcom::bool_t aIsVoid);

_XPCOM_API(xpcom::bool_t)
NS_CStringGetIsVoid(const xpcom::string& aStr);
#endif // XPCOM_API_VERSION >= XPCOM_API_VERSION_1_9

// Encodings that can be used with the following conversion routines.
enum nsCStringEncoding
{
    NS_CSTRING_ENCODING_ASCII = 0,
    NS_CSTRING_ENCODING_UTF8 = 1,
    NS_CSTRING_ENCODING_NATIVE_FILESYSTEM = 2
};

_XPCOM_API(xpcom::result_t)
NS_CStringToUTF16(
        const xpcom::string& aSource,
        nsCStringEncoding aSrcEncoding,
        xpcom::wstring& aDest);

_XPCOM_API(xpcom::result_t)
NS_UTF16ToCString(
        const xpcom::wstring& aSource,
        nsCStringEncoding aDestEncoding,
        xpcom::string& aDest);

#endif // XPCOM_API_STRING_HPP
